ifeq ($(OS),Windows_NT)
	LIBGTEST=libgtest.dll
else
	LIBGTEST=libgtest.so
endif

leetcode: $(LIBGTEST) main.cpp *.h
	g++ --coverage -std=c++11 -g -o $@ main.cpp -L./ -lgtest -lpthread -Wl,-rpath,'$${ORIGIN}'

$(LIBGTEST): gmock-gtest-all.cc gtest.h gmock.h
	g++ --coverage gmock-gtest-all.cc -fPIC -shared -o $@

coverage: leetcode
	./leetcode
	mkdir -p ./coverage_report
	lcov -c -d . -b . -o ./coverage_report/leetcode.lcov --no-external
	genhtml ./coverage_report/leetcode.lcov -o ./coverage_report

PHONY: clean
clean:
	rm -f leetcode
	rm -f $(LIBGTEST)

